<?php

   /* $str = '<span class="zm-profile-section-name"><a href="/people/xxx">xxxx</a> 被 21 人关注</span>';

    if(preg_match('|\s(\d)+\s|',$str,$matches)){
        print_r($matches);

    }*/

    require __DIR__."/../vendor/autoload.php";


    \ActiveRecord\Config::initialize(function($DbConfig)  {
        $DbConfig->set_model_directory( '../Core/Models');
        $DbConfig->set_connections([
            'development' =>'mysql://root:@192.168.1.115/lactone?charset=utf8'
        ]);
    });

    \lactone\Core\Models\TaskModel::create(['hash'=>'123','url' =>'asd','request'=>'asd','status'=>0]);
    exit;

    $Queue_Driver           = 'File';
    $Queue_DriverArgs       = [
        'file'    => 'asdasd'
    ];

    Lactone::setConfigs([
        'log' =>[
            'handler'=>'file',
            'name'   =>__DIR__.'/log',
            'conf'   =>[
                'timeFormat' =>'%m %d %H:%M:%S'
            ],
        ],
        'TaskQueue' =>[
            'Driver'     => $Queue_Driver,
            'DriverArgs' => array_merge($Queue_DriverArgs,['key'=>'taskQueue']),
        ],
        'taskCompleteQueue' =>[
            'Driver'     => $Queue_Driver,
            'DriverArgs' => array_merge($Queue_DriverArgs,['key'=>'taskQueue']),
        ]
    ]);

    Lactone::initLog();

    set_error_handler(array('Lactone','error_handle'));


    $Data = [];

    $Site = new \Spider\Site\zhihu_com([
        'task'=>[
            'url'       =>'http://www.zhihu.com',
            'request'   => [],
        ],
         'CookieDir' =>__DIR__.'/'
    ]);



    if(!$Site->send()){
        //任务执行失败
    }else{
        //任务执行成功
    }
    exit;

    $Client = new \GuzzleHttp\Client([
        'base'      => 'http://www.zhihu.com',
        'timeout'   => 3.0,
        'cookie'    => new GuzzleHttp\Cookie\FileCookieJar(__DIR__.'/cookie')
    ]);


    $respone = $Client->get("http://www.zhihu.com");

    $html =  $respone->getBody();

    //$html = '<ul><li>First</li><li>Second</li><li>Third</li></ul>';

    $Doc  = new \DOMWrap\Document();

    $nodeList = $Doc->html($html->getContents())->find(".view-signin");

    print_r($nodeList->count());

